# Table B.4: Effect of Ordered Net Benefits on Turnout with Binary Utility Measures for Voters


# 1. Load Packages ----

library(tidyverse)
library(lfe)
library(stargazer)

# 2. Read in Data ----

load(file = "df_voxit_individual_analysis.RData")

# 3. Data Preparation ----
voxit_individual <- voxit_individual %>%
  mutate(sum_binary1 = ifelse(utility_optc_sum>0, 1, 0),
         max_binary1 = ifelse(utility_optc_max>0, 1, 0),
         utility_binary_1st = ifelse(utility_prop_1st>0, 1, 0),
         utility_binary_2nd = ifelse(utility_prop_2nd>0, 1, 0),
         utility_binary_3rd = ifelse(utility_prop_3rd>0, 1, 0),
         utility_binary_4th = ifelse(utility_prop_4th>0, 1, 0),
         utility_binary_5th = ifelse(utility_prop_5th>0, 1, 0),
         utility_binary_6th = ifelse(utility_prop_6th>0, 1, 0))


# 4. Conduct Regressions ----
lm.mainb1 <- felm(turnout ~ utility_binary_1st +
                    male + married + age + uni + knowledge  + leftright +
                    initiative + initiative_counter + referendum_fak + 
                    referendum_comp | 
                    canton_id + year | 0 | canton_id + datum_merge, 
                  data = voxit_individual[voxit_individual$prop_voxit==1 ,])
summary(lm.mainb1)

lm.mainb2 <- felm(turnout ~ utility_binary_1st + utility_binary_2nd + 
                    male + married + age + uni + knowledge  + leftright +
                    initiative + initiative_counter + referendum_fak + 
                    referendum_comp | 
                    canton_id + year | 0 | canton_id + datum_merge, 
                  data = voxit_individual[voxit_individual$prop_voxit==2 ,])
summary(lm.mainb2)

lm.mainb3 <- felm(turnout ~ utility_binary_1st + utility_binary_2nd + utility_binary_3rd +
                    male + married + age + uni + knowledge  + leftright +
                    initiative + initiative_counter + referendum_fak + 
                    referendum_comp | 
                    canton_id + year | 0 | canton_id + datum_merge, 
                  data = voxit_individual[voxit_individual$prop_voxit==3 ,])
summary(lm.mainb3)

lm.mainb4 <- felm(turnout ~ utility_binary_1st + utility_binary_2nd + utility_binary_3rd +
                    utility_binary_4th +
                    male + married + age + uni + knowledge  + leftright +
                    initiative + initiative_counter + referendum_fak + 
                    referendum_comp | 
                    canton_id + year | 0 | canton_id + datum_merge, 
                  data = voxit_individual[voxit_individual$prop_voxit==4 ,])
summary(lm.mainb4)

lm.mainb5 <- felm(turnout ~ utility_binary_1st + utility_binary_2nd + utility_binary_3rd +
                    utility_binary_4th + utility_binary_5th +
                    male + married + age + uni + knowledge  + leftright + 
                    initiative + initiative_counter + referendum_fak + 
                    referendum_comp | 
                    canton_id + year | 0 | canton_id + datum_merge , 
                  data = voxit_individual[voxit_individual$prop_voxit==5 ,])
summary(lm.mainb5) # includes 11 voting days

lm.mainb6 <- felm(turnout ~ utility_binary_1st + utility_binary_2nd + utility_binary_3rd +
                    utility_binary_4th + utility_binary_5th +  utility_binary_6th +
                    male + married + age + uni + knowledge  + leftright +
                    initiative + initiative_counter + referendum_fak + 
                    referendum_comp | 
                    canton_id + year | 0 | canton_id , # not clustered on day level
                  data = voxit_individual[voxit_individual$prop_voxit==6,])
summary(lm.mainb6) # includes only 2 voting days

# 5. Regression Table ----

stargazer(lm.mainb1, lm.mainb2, lm.mainb3, lm.mainb4, lm.mainb5, 
          type = "latex", star.cutoffs = c(0.1, 0.05, 0.01),
          star.char = c("*", "**", "***"),
          summary=T, df = F, float = F,
          keep = "^utility_binary",
          covariate.labels = c("1\\{U^{1st}>0\\} ", "1\\{U^{2nd}>0\\}",
                               "1\\{U^{3rd}>0\\}", "1\\{U^{4th}>0\\}",
                               "1\\{U^{5th}>0\\}", "1\\{U^{6th}>0\\}"),
          dep.var.caption="Dependent variable: Turnout",
          add.lines = list(c("\\# of propositions", "1", "2", "3", "4", "5"),
                           c("\\# of voting days", 
                             length(unique(voxit_individual[voxit_individual$prop_voxit==1,]$datum_merge)),
                             length(unique(voxit_individual[voxit_individual$prop_voxit==2,]$datum_merge)),
                             length(unique(voxit_individual[voxit_individual$prop_voxit==3,]$datum_merge)),
                             length(unique(voxit_individual[voxit_individual$prop_voxit==4,]$datum_merge)),
                             length(unique(voxit_individual[voxit_individual$prop_voxit==5,]$datum_merge)))),
          dep.var.labels.include=F,
          omit.table.layout ="n",
          keep.stat = c("n"),
          out = "TableB4.tex")
